

Ext.define('UDZ.controller.Ctr_Address_manger', {
    extend: 'Ext.app.Controller',

    config: {
        refs: {
            addressview:{
                selector:'address',
                xtype:'address',
                autoCreate:true
            },
            AddrssBack:'#address_back',//返回个人中心
            AddAddress:'#add_address', //添加收货地址
            ChangeAddress:'#go_change_address', //添加收货地址

        },
        control:{
            AddrssBack:{
                tap:'func_AddressBack'
            },
            AddAddress:{
                initialize:'func_AddAddress'
            },
            ChangeAddress:{
              //  initialize:'func_ChangeAddress'
            }

        },
        routes:{ //自己的路由
            'route_address_manger':'showAddressManger',
            // 'route/:AddressId':''
        }
    },
    showAddressManger:function (){
       // Ext.Viewport.setActiveItem(this.getAddressview());
        Ext.Viewport.animateActiveItem(this.getAddressview(),{type:'slide',duration:500,direction:'left'});

        var address = Ext.getStore('Store_Address');
        address.load({
            callback: function (records, operation, success) {
                if (success) {
                    var tplAddress = new Ext.XTemplate(
                        '<tpl for=".">'+
                          '<div class="address_container" id="address_{AddressId}" onclick="location.href=\'#route_address_change/{AddressId}\';sessionStorage.setItem(\'admin\',\'{UserName}\')"> ' +
                             '<div class="address_content"> ' +
                                '<div class="address_name"> ' +
                                  '<span class="address_span_name">{UserName}</span> ' +
                                  '<span class="address_span_Tel">{UserTel}</span> ' +
                                '</div> ' +
                                '<div class="address_detail">{address}</div> ' +
                             '</div> ' +
                             '<div class="address_righrt"><img src=" resources/images/right.png" alt=""></div>'+
                        '<div>'+
                        '</tpl>'
                    )
                var addressList = Ext.getCmp('go_change_address');
                    addressList.setItemTpl(tplAddress);
                    addressList.setStore(this);
                }
            }
        })
        // for (var i=1;i<address.length;i++){
            document.getElementById('address_1').addEventListener('click',function(){
                alert('hello world')
            },false);
        // }
    },
    func_AddressBack:function () {
        this.redirectTo('route_main');
    },
   //  func_ChangeAddress:function () {
   //      var me=this;
   // /*     Ext.getCmp('go_change_address').element.on({
   //          itemtap : function( ) { //点击事件
   //             // me.redirectTo('route_address_change');
   //
   //
   //          },
   //
   //      });*/
   //  },
    func_AddAddress:function () {
        var me=this;
        Ext.getCmp('add_address').element.on({
            tap : function( ) { //点击事件
                me.redirectTo('route_address_add');
                location.href='#route_address_change/7';sessionStorage.removeItem('admin');
            }
        });
    }
});